<?php 
$this->load->view('admin/layout/head', array('title'=>'品牌管理','nav'=>'product'), FALSE);
?>

<div id="container">
<ul class="nav nav-tabs" id="subject-tab">
	<li class="active"><a href="javascript:;"><?= $this->lang->line('create').$this->lang->line('brand') ?></a></li>
</ul>
<?= form_open('', [
	'class' => 'form-inline deal-from container-fluid no-padding',
	'id' => 'brand-form',
]); ?>

	<div class="mt-20">
		<label for=""><?= $this->lang->line('brand_title') ?></label>
		<div class="form-group">
			<input type="text" name="title" class="form-control" value="<?= set_value('title', $brand['title']) ?>" style="width: 600px">
		</div>
		<?= form_error('title', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('brand_en_title') ?></label>
		<div class="form-group">
			<input type="text" name="en_title" class="form-control" value="<?= set_value('en_title', $brand['en_title']) ?>" style="width: 600px">
		</div>
		<?= form_error('en_title', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('image') ?></label>
		<div class="form-group" >
			<a href="javascript:;" class="btn btn-primary" id='up-btn'><?= $this->lang->line('choose_image') ?></a>
			<input type="hidden" name='image' id="brand-image"  value="<?= set_value('image', $brand['image']) ?>">
			<div id="up-container">
				<?php if ($brand['image']): ?>
				<img src="<?= set_value('image', $brand['image']) ?>" alt="" style="max-width: 600px; max-height: 100px"/>
				<?php endif; ?>
			</div>
		</div>
		<?= form_error('image', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('contains_the_categories') ?></label>
		<div class="form-group" >
			<?php $brand_categorys = set_value('categories', $brand['categories']) ? explode(',', set_value('categories', $brand['categories'])) : []; ?>
			<?php foreach ($categories as $cate):?>
			<input type="checkbox" name="categories[]" value="<?php echo $cate['id']?>" <?php if(isset($brand) && in_array($cate['id'],$brand_categorys)) echo 'checked' ?>> <?php echo $cate['title'] ?>
			<?php endforeach; ?>
		</div>
		<?= form_error('categories', '<div class="text-danger">', '</div>') ?>
	</div>
	<div class="mt-20">
		<label for=""><?= $this->lang->line('sort'); ?></label>
		<div class="form-group" >
			<input type="text" name="sort" class="form-control" value="<?= set_value('sort', $brand['sort']); ?>" style="width: 100px">
		</div>
		<?= form_error('sort', '<div class="text-danger">', '</div>') ?>
	</div>
	
	<div style="padding-left:110px" class="mt-20">
      <button class="btn btn-primary save"><?= $this->lang->line('save') ?></button>
      <a onclick="window.history.go(-1);" class="btn btn-default cancel"><?= $this->lang->line('cancel') ?></a>
    </div>
<?= form_close() ?>
</div>


<?php 
$js_array = array(
	'/assets/plupload/plupload.full.min.js'
	);
$this->load->view('admin/layout/footer',array('js'=>$js_array));
?>
<script type="text/javascript">

	$(function(){
		uploadImg('up-btn',function(img){
			$('#up-container').html('<img src="'+img+'" style="max-width: 600px; max-height: 100px"/>');
			$('#brand-image').val(img);
		});
	})
	
	$('.save').click(function(event) {		
		if(!$('input[name=title]').val()){
			alert('请填写品牌名称');
			return false;
		}
	});
</script>